﻿namespace Colorful.Caching;

/// <summary>
///  redis缓存
/// </summary>
public interface IRedisCache
{
    /// <summary>
    ///  改变数据库
    /// </summary>
    /// <param name="dbValue">数据值</param>
    /// <returns></returns>
    IRedisCache ChangeDb(int dbValue);

    /// <summary>
    ///  设置缓存
    /// </summary>
    /// <typeparam name="T">泛型</typeparam>
    /// <param name="key">redis键</param>
    /// <param name="value">redis值</param>
    /// <param name="expireSeconds">过期时间，默认为不过期</param>
    /// <returns></returns>
    Task<bool> SetAsync<T>(string key, T value, int expireSeconds = -1);

    /// <summary>
    ///  设置缓存
    /// </summary>
    /// <typeparam name="T">泛型</typeparam>
    /// <param name="key">redis键</param>
    /// <param name="value">redis值</param>
    /// <param name="expireSeconds">过期时间，默认为不过期</param>
    /// <returns></returns>
    bool Set<T>(string key, T value, int expireSeconds = -1);

    /// <summary>
    ///  从缓存中获取泛型的方法
    /// </summary>
    /// <typeparam name="T">泛型</typeparam>
    /// <param name="key">键</param>
    /// <returns>T?</returns>
    Task<T?> GetAsync<T>(string key);

    /// <summary>
    ///  从缓存中获取泛型的方法
    /// </summary>
    /// <typeparam name="T">泛型</typeparam>
    /// <param name="key">redis键</param>
    /// <returns>T?</returns>
    T? Get<T>(string key);

    /// <summary>
    ///  删除缓存
    /// </summary>
    /// <param name="key">redis键</param>
    /// <returns></returns>
    bool Delete(string key);

    /// <summary>
    ///  删除缓存
    /// </summary>
    /// <param name="key">redis键</param>
    /// <returns></returns>
    Task<bool> DeleteAsync(string key);
}